import pulpcore.Stage;
import pulpcore.animation.Easing;
import pulpcore.animation.Timeline;
import pulpcore.animation.event.SceneChangeEvent;
import pulpcore.image.BlendMode;
import pulpcore.image.CoreImage;
import pulpcore.scene.Scene2D;
import pulpcore.sprite.Group;
import pulpcore.sprite.ImageSprite;
import pulpcore.sprite.Sprite;


public class MainScene extends Scene2D
{

	Menus.MainMenu mm;
	private StarField sf;
	private TwoPlayerScene tp; 
	@Override
	public void load()
	{
		super.load();
		
		Sounds s = new Sounds();
		
		Group g = new Group();
		add(g);
		g.add(new ImageSprite("bg.jpg", 0,0,Stage.getWidth(),Stage.getHeight()));
		sf = new StarField();
		g.add(sf);
		
		g.alpha.animate(0, 255, 200);
		
		mm = new Menus.MainMenu();
		mm.setLocation(-Stage.getWidth()*.5, Stage.getHeight()/2+60);
		mm.x.animate(mm.x.get(), Stage.getWidth()/2, 1500,Easing.STRONG_OUT);
		mm.angle.animate(-Math.PI, 0, 1500,Easing.STRONG_OUT);
		add(mm);
		
		ImageSprite logo = new ImageSprite(CoreImage.load("logo.png"),0,0);
		logo.setAnchor(Sprite.CENTER);
		logo.setLocation(Stage.getWidth()/2, -logo.height.get());
		logo.y.animateTo(logo.height.get()/2+10, 500,Easing.STRONG_OUT);
		logo.setBlendMode(BlendMode.Add());
		logo.alpha.set(180);
		add(logo);
		
		tp = new TwoPlayerScene();
		tp.load();
	}
	
	@Override
	public void update(int elapsedTime)
	{
		super.update(elapsedTime);
		
		if (mm.play.isClicked())
		{
			mm.x.animate(mm.x.get(), Stage.getWidth()*1.5, 1500,Easing.STRONG_OUT);
			mm.angle.animate(0, Math.PI, 1500,Easing.STRONG_OUT);
			Timeline t = new Timeline();
			tp.setStarfield(sf);
			tp.setWinningScore(mm.slider.value.getAsInt());
			t.addEvent(new SceneChangeEvent(tp,1600,false));
			addTimeline(t);
		}
	}
	
}
